﻿using Nasty.Core.Session;
using Nasty.Core.Entity;
using Nasty.Core.Entity.System;
using SqlSugar;
using Nasty.Core.Attributes;

namespace Nasty.Core.Entity.Flow
{
    [SugarTable("SysFlowConfigNode", TableDescription = "流程配置节点")]
    public class FlowConfigNode : StandardEntity<FlowConfigNode>
    {
        /// <summary>
        /// 流程配置Id
        /// </summary>
        [NastyColumn(ColumnName = "FlowConfigId", ColumnDescription = "流程配置Id", Required = true)]
        public string? FlowConfigId { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [NastyColumn(ColumnName = "Name", ColumnDescription = "名称", Required = true)]
        public string? Name { get; set; }

        /// <summary>
        /// 编码
        /// </summary>
        [NastyColumn(ColumnName = "Code", ColumnDescription = "编码", IsRepeat = true, RepeatLink = "FlowConfigId")]
        public string? Code { get; set; }


        /// <summary>
        /// 上一个节点Codes
        /// </summary>
        [NastyColumn(ColumnName = "PreNodeCodes", IsJson = true, IsNullable = true, ColumnDescription = "上一个节点Codes", ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public List<string> PreNodeCodes { get; set; }

        /// <summary>
        /// 驳回节点Code
        /// </summary>
        [NastyColumn(ColumnName = "RejectNodeCode", IsNullable = true, ColumnDescription = "驳回节点Code")]
        public string? RejectNodeCode { get; set; }

        /// <summary>
        /// 位置X
        /// </summary>
        [NastyColumn(ColumnName = "PositionX", ColumnDescription = "位置X")]
        public int PositionX { get; set; }

        /// <summary>
        /// 位置Y
        /// </summary>
        [NastyColumn(ColumnName = "PositionY", ColumnDescription = "位置Y")]
        public int PositionY { get; set; }


        /// <summary>
        /// 候选模式
        /// </summary>
        [SugarColumn(ColumnName = "CandidateMode", ColumnDescription = "候选模式")]
        public CandidateMode CandidateMode { get; set; }


        /// <summary>
        /// 预选用户Ids
        /// </summary>
        [SugarColumn(ColumnName = "PreUserIds", IsJson = true, IsNullable = true, ColumnDescription = "预选用户Ids", ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public List<string> PreUserIds { get; set; }


        ///// <summary>
        ///// 预选用户
        ///// </summary>
        [Navigate(NavigateType.OneToManyByArrayList, nameof(PreUserIds))]
        public List<User> PreUsers { get; set; }



        /// <summary>
        /// 角色Ids
        /// </summary>
        [SugarColumn(ColumnName = "RoleIds", IsJson = true, IsNullable = true, ColumnDescription = "角色Ids", ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public List<string> RoleIds { get; set; }

        ///// <summary>
        ///// 角色
        ///// </summary>
        [Navigate(NavigateType.OneToManyByArrayList, nameof(RoleIds))]
        public List<Role> Roles { get; set; }

        /// <summary>
        /// 部门Ids
        /// </summary>
        [SugarColumn(ColumnName = "DepartmentIds", IsJson = true, IsNullable = true, ColumnDescription = "部门Ids", ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public List<string> DepartmentIds { get; set; }


        ///// <summary>
        ///// 部门
        ///// </summary>
        [Navigate(NavigateType.OneToManyByArrayList, nameof(DepartmentIds))]
        public List<Department> Departments { get; set; }

        public override void OnPreAdd()
        {
            base.OnPreAdd();
            var db = AppSession.CurrentDb.Value;
        }
    }


    public enum CandidateMode : byte
    {
        /// <summary>
        /// 任意用户
        /// </summary>
        User = 1,
        /// <summary>
        /// 预选用户
        /// </summary>
        PreUser = 2,
        /// <summary>
        /// 角色
        /// </summary>
        Role = 3,
        /// <summary>
        /// 部门
        /// </summary>
        Department = 4,
        /// <summary>
        /// 触发器
        /// </summary>
        Action = 5,
    }
}
